Model examples
This is a set of example models.
- Bare-bones model
- Adding repr()
- Giving models custom methods
- Many-to-one relationships
- Many-to-many relationships
- Specifying ordering
- The lookup API
- Getting the "latest" object
- Many-to-many relationships via an intermediary table
- One-to-one relationships
- Relating an object to itself, many-to-one
- Relating a model to another model more than once
- Adding hooks before/after saving and deleting
- Using a custom primary key
- Subclassing models
- Many-to-one relationships that can be null
- Custom column names
- Using SQL reserved names
